<div class="container-fluid">
    <div id="pad-wrapper">
        <!-- products table-->
        <!-- the script for the toggle all checkboxes from header is located in js/theme.js -->
        <div class="table-wrapper products-table section">
            <div class="row-fluid head">
                <div class="span12">
                    <h4>样本管理</h4>
                </div>
            </div>


            <form action="" method="get" name="search">
                <div class="row-fluid filter-block">
                    <!--
                    <div class="pull-left">
                        <a class="btn-flat success" onclick="document.forms['batch'].submit();">批量通过</a>
                    </div> -->
                    <div class="pull-right">
                        订单编号：
                        <input type="text" name="order_no" value="<?php echo $order_no; ?>"></input>
                        样本编号：
                        <input type="text" name="bind_no" value="<?php echo $bind_no; ?>"></input>
                        样本状态：
                        <select name="smaple_status"  style="cursor: default;margin-right:20px" class="search">
                            <option value ="0">所有</option>
                            <?php
                            foreach($samplestatus as $key => $value)
                            {
                                if($smaple_status == $key){
                                    echo "<option value =" . $key ."  selected = \"selected\">".$value  ."</option>";
                                }else{
                                    echo "<option value =" . $key .">".$value  ."</option>";
                                }
                            }
                            ?>
                        </select>
                        回寄单号：
                        <input type="text" name="tracking_no" value="<?php echo $tracking_no; ?>"></input>
                        <a class="btn-flat success" id="search" onclick="document.forms['search'].submit();">查询</a>
                    </div>
                </div>
            </form>

            <div class="row-fluid">
                <table class="table table-hover">
                    <thead>

                    <tr>
                        <!-- <th class="span3"><input type="checkbox" /> 头像</th> -->
                        <th class="span1"><span class="line"></span>订单号</th>
                        <th class="span2"><span class="line"></span>样品编号</th>
                        <th class="span2"><span class="line"></span>姓名</th>
                        <th class="span2"><span class="line"></span>性别</th>
                        <th class="span2"><span class="line"></span>出生年月</th>
                        <th class="span2"><span class="line"></span>样本回寄快递</th>
                        <th class="span1"><span class="line"></span>样本状态</th>
                        <th class="span1"><span class="line"></span>操作</th>
                    </tr>

                    </thead>
                    <form action="/shop-order/batch" method="post" name="batch">
                        <tbody>

                        <?php if ($list): ?>
                            <?php foreach ($list as $k=>$item): ?>
                                <!-- row -->
                                <tr class="first" id="<?php echo $item['bid_id'] ?>">
                                    <td class="order_no"><?php echo $item['order_no'] ?></td>
                                    <td class="bind_no"><?php echo $item['bind_no'] ?></td>
                                    <td class="name"><?php echo $item['name'] ?></td>
                                    <td class="name"><?php echo $item['sex'] ?></td>
                                    <td class="name"><?php echo $item['birthday'] ?></td>
                                    <td class="name"><?php echo $item['company_name'].' | '.$item['tracking_no'] ?></td>
                                    <td class="bind_status"><?php
                                        echo $samplestatus[$item['bind_status']];
                                        ?></td>
                                    <td class="options">
                                        <?php if ($item['bind_status'] == 1): ?>
                                            <!--

                                            <button class=" btn-flat primary" id="cz" data-toggle="modal" data-target="#<?php echo $item['bid_id'].'Model' ?>" style="background-color: #3b9ff3">
                                                录入编号
                                            </button>

                                            <div class="modal fade" id="<?php echo $item['bid_id'].'Model' ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                <div class="modal-dialog">
                                                    <div class="modal-content">
                                                        <div class="modal-body">
                                                            订单号:<?php echo $item['order_no'] ?> ?>
                                                        </div>
                                                    </div>
                                                    <div class="modal-content">
                                                        <div class="modal-body">
                                                            录入编号:<input type="text" id="<?php echo $item['bid_id'] ?>_bind_no"/>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                                            </button>
                                                            <button type="button" class="btn btn-primary" id=""  data-dismiss="modal" onclick="copyText('<?php echo $item['bid_id'] ?>')">
                                                                提交更改
                                                            </button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            -->
                                       <!--     <button type="button" class=" btn-flat primary"
                                                    onclick="window.location.href='/sample/lrno?id=<?php echo $item['bid_id'] ?>'">
                                                录入编号
                                            </button></li> -->
                                        <?php endif; ?>
                                        <button type="button" class=" btn-flat primary" onclick="window.location.href='/sample/sampleinfo?bind_id=<?php echo $item['bid_id']?>'">详细</button>
                                        </li>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                        </tbody>
                    </form>
                </table>
            </div>
        </div>
        <!-- end products table -->
    </div>
    <div class="pagination pull-right">
        <?php echo $pagination; ?>
    </div>
    <!--Edited by ysy Start-->
    <script type="text/javascript">
        $(function () {
            <!--表格标题点击排序-->
            $("th.clickable").click(function () {
                var param = $(this).data("param");
                if (!$("th.clickable .icon.icon-chevron-down").length > 0) {
                    $(this).find(".icon").addClass("icon-chevron-down").removeClass("icon-chevron-up");
                    var $namev = $('input[name="wx_name"]').val();
                    var $start_time = $('input[name="start_time"]').val();
                    var $end_time = $('input[name="end_time"]').val();
                    var $smaple_status = $('input[name="smaple_status"]').val();
                    var $url = '/spread/index?wx_name=' + $namev + "&sort_num=desc" + "&start_time=" + $start_time +"&smaple_status=" + $smaple_status + "&end_time=" + $end_time;
                    $.ajax({
                        type: 'get',
                        url: $url,
                        cache: false,
                        dataType: 'json',
                        success: function (data) {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        },
                        error: function () {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        }
                    });
                }
                else {
                    $(this).find(".icon").addClass("icon-chevron-up").removeClass("icon-chevron-down");
                    var $namev = $('input[name="wx_name"]').val();
                    var $start_time = $('input[name="start_time"]').val();
                    var $end_time = $('input[name="end_time"]').val();
                    var $smaple_status = $('input[name="smaple_status"]').val();
                    var $url = '/spread/index?wx_name=' + $namev + "&sort_num=asc" + "&start_time=" + $start_time+"&smaple_status=" + $smaple_status + "&end_time=" + $end_time;
                    $.ajax({
                        type: 'get',
                        url: $url,
                        cache: false,
                        dataType: 'json',
                        success: function (data) {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        },
                        error: function () {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        }
                    });
                }
            });

            /*
             时间排序事件
             */
            $("th.clickable_time").click(function () {
                var param = $(this).data("param");
                if (!$("th.clickable_time .icon.icon-chevron-down").length > 0) {
                    $(this).find(".icon").addClass("icon-chevron-down").removeClass("icon-chevron-up");
                    var $namev = $('input[name="wx_name"]').val();
                    var $start_time = $('input[name="start_time"]').val();
                    var $end_time = $('input[name="end_time"]').val();
                    var $smaple_status = $('input[name="smaple_status"]').val();
                    var $url = '/spread/index?wx_name=' + $namev + "&sort_time=desc" + "&start_time=" + $start_time + "&smaple_status=" + $smaple_status + "&end_time=" + $end_time;
                    $.ajax({
                        type: 'get',
                        url: $url,
                        cache: false,
                        dataType: 'json',
                        success: function (data) {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        },
                        error: function () {
//						window.location.reload($url);//刷新当前页面.
                            location.href = $url;
                        }
                    });
                }
                else {
                    $(this).find(".icon").addClass("icon-chevron-up").removeClass("icon-chevron-down");
                    var $namev = $('input[name="wx_name"]').val();
                    var $start_time = $('input[name="start_time"]').val();
                    var $end_time = $('input[name="end_time"]').val();
                    var $smaple_status = $('input[name="smaple_status"]').val();
                    var $url = '/spread/index?wx_name=' + $namev + "&sort_time=asc" + "&start_time=" + $start_time + "&smaple_status=" + $smaple_status + "&end_time=" + $end_time;
                    $.ajax({
                        type: 'get',
                        url: $url,
                        cache: false,
                        dataType: 'json',
                        success: function (data) {
                            location.href = $url;
                        },
                        error: function () {
                            location.href = $url;
                        }
                    });
                }
            });
        });
    </script>

    <script type="text/javascript">
        function copyText(bind_id){
            var $bind_no =$("#"+bind_id+"_bind_no").val();
            var $smaple_status = $('input[name="smaple_status"]').val();
            var $url = '/sample/ajaxlrno?bind_id=' + bind_id+"&smaple_status=" + $smaple_status + '&bind_no='+$bind_no;
            $.ajax({
                type: 'get',
                url: $url,
                cache: false,
                dataType: 'json',
                success: function (data) {
                    if(data.error == 1)
                    {
                        alert(data.msg);
                    }else {
                        //修改页面内容
                        change(data);
                    }
                },

                error: function () {
                    alert("系统繁忙，请联系客服！400-821-0418");
                }
            });
        }

        //改变记录页面显示
        function change(data)
        {
//            $("#"+data['bind_id']+'Model').modal('hide');
            var status='';
            if (data['bind_status'] == 1) {
                status= '订单未确认';
            } else if (data['bind_status'] == 2) {
                status=  '采样盒寄出';
            } else if (data['bind_status'] == 3) {
                status=  '样本已绑定';
            }else if (data['bind_status'] == 4) {
                status=  '检查中';
            }else if (data['bind_status'] == 5) {
                status=  '待处理';
            }else if (data['bind_status'] == 6) {
                status=  '已出报告';
            }
            $("#"+data['bind_id']+" .bind_no").text(data['bind_no']);
            $("#"+data['bind_id']+" .bind_status").text(status);
            $("#"+data['bind_id']+" #cz").remove();

        }
    </script>

    <style>
        th {
            text-align: center !important;
        }

        table td {
            text-align: center !important;
        }

        table th span.line {
            left: 0 !important;
        }

        th.clickable {
            cursor: pointer;
        }

        th.clickable_time {
            cursor: pointer;
        }

        th.clickable .icon {
            margin-left: 10px;
        }

        th.clickable_time .icon {
            margin-left: 10px;
        }
    </style>
    <!--Edited by ysy End-->
</div>